package com.haidechizi.designpattern.strategy.extension;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author haidechizi
 */
public class BarCodeFactory {

    private static final Map<String, BarCodeAnalysis> analysisHolder = new ConcurrentHashMap<>();

    public static void addAnalysis(String type, BarCodeAnalysis barCodeAnalysis) {
        analysisHolder.put(type, barCodeAnalysis);
    }

    public static BarCodeAnalysis getAnalysis(String type) {
        return Optional.ofNullable(analysisHolder.get(type)).orElse(analysisHolder.get("default"));
    }
}
